<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='评论管理',active='comments'">
<header th:replace="back/header::headerFragment(${title},${active})"></header>
<head>
  <meta th:name="_csrf" th:content="${_csrf.token}"/>
  <!-- 默认的header name是X-CSRF-TOKEN -->
  <meta th:name="_csrf_header" th:content="${_csrf.headerName}"/>
</head>
<body class="fixed-left">
<div id="wrapper">
  <div th:replace="back/header::header-body"></div>
  <div class="content-page">
    <div class="content">
      <div class="container">
        <div class="row">
          <div class="col-sm-12">
            <h4 class="page-title">评论管理</h4>
          </div>
          <div class="col-md-12">
            <table class="table table-striped table-bordered">
              <thead>
              <tr>
                <th width="45%">评论内容</th>
                <th width="15%">评论时间</th>
                <th>作者</th>

                <th>操作</th>
              </tr>
              </thead>
              <tbody>
              <th:block th:each="comments : ${comments.list}">
                <tr th:id="${comments.id}">
                  <td>
                    <a  th:text="${comments.content}" target="_blank"></a>
                  </td>
                  <td><th:block th:text="${commons.dateFormat(comments.created)}"/></td>
                  <td><th:block th:text="${comments.author}"/></td>
                  <td>

                    <a href="javascript:void(0)" th:onclick="'delComment('+${comments.id}+');'"
                       class="btn btn-danger btn-sm waves-effect waves-light m-b-5">
                      <i class="fa fa-trash-o"></i> <span>删除</span></a>
                    <a class="btn btn-warning btn-sm waves-effect waves-light m-b-5" th:href="@{'/article/'+${comments.articleId}}" href="javascript:void(0)">
                      <i class="fa fa-rocket"></i> <span>查看所属文章</span></a>

                  </td>
                </tr>
              </th:block>

              </tbody>
            </table>
            <div th:replace="comm/paging :: pageAdminNav(${comments})"></div>
          </div>
        </div>
        <div th:replace="back/footer :: footer-content"></div>
      </div>
    </div>
  </div>
</div>
<div th:replace="back/footer :: footer"></div>
<script type="text/javascript">
  /*<![CDATA[*/
  function delComment(id) {
    // 获取<meta>标签中封装的_csrf信息
    var token = $("meta[name='_csrf']").attr("content");
    var header = $("meta[name='_csrf_header']").attr("content");
    if(confirm('确定删除该评论吗?')){
      $.ajax({
        type:'post',
        url : '/admin/comment/delete',
        data: {id:id},
        dataType: 'json',
        beforeSend : function(xhr) {
          xhr.setRequestHeader(header, token);
        },
        success: function (result) {
          if (result && result.success) {
            window.alert("评论删除成功");
            window.location.reload();
          } else {
            window.alert(result.msg || '评论删除失败')
          }
        }
      });
    }
  }
  /*]]>*/
</script>
</body>
</html>